import type { LoginForm, Pagination } from "../types";
import http from "@/utils/http";

// 获取验证码
export function captcha() {
  return http({
    method: "GET",
    url: "/captcha",
    data: { isBase64: 1 },
  });
}

// 登录
export function login(loginForm: LoginForm) {
  return http({
    method: "GET",
    url: "/login",
    data: loginForm,
  });
}

//  微信登录
export function loginWx(code: string) {
  return http({
    method: "GET",
    url: "/login-wx",
    data: { code },
  });
}

// 绑定微信
export function bindWx(code: string) {
  return http({
    method: "GET",
    url: "/bind-wx",
    data: { code },
  });
}

// 获取用户信息
export function member() {
  return http({
    method: "GET",
    url: "/member",
  });
}

// 获取记录列表
export function queryRecords(data: Pagination) {
  return http({
    method: "GET",
    url: "/things",
    data,
  });
}

// 创建记录
export function createRecord(data: any) {
  return http({
    method: "POST",
    url: "/things",
    data,
  });
}

// 批量创建记录
export function createRecordBatch(data: any) {
  return http({
    method: "POST",
    url: "/things/batch",
    data,
  });
}

// 获取今日统计
export function todayStatistic() {
  return http({
    method: "GET",
    url: "/statistic/today",
  });
}

// 获取记录选项
export function queryThingOptions() {
  return http({
    method: "GET",
    url: "/thing-options",
  });
}

// 创建记录选项
export function createThingOption(form: any) {
  return http({
    method: "POST",
    url: "/thing-options",
    data: form,
  });
}

// 记录选项详情
export function getThingOption(id: number) {
  return http({
    method: "GET",
    url: "/thing-options/" + id,
  });
}

// 记录选项更新
export function updateThingOption(id: number, form: any) {
  return http({
    method: "PUT",
    url: "/thing-options/" + id,
    data: form,
  });
}
